<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Searches the language tag list for the best match to the language</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="locale.getscript.html">« Locale::getScript</a></li>
      <li style="float: right;"><a href="locale.parselocale.html">Locale::parseLocale »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.locale.html">Locale</a></li>
    <li>Searches the language tag list for the best match to the language</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="locale.lookup" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Locale::lookup</h1>
  <h1 class="refname">locale_lookup</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Locale::lookup</span> -- <span class="refname">locale_lookup</span> &mdash; <span class="dc-title">Searches the language tag list for the best match to the language</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-locale.lookup-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>Locale::lookup</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$languageTag</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$canonicalize</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$defaultLocale</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>locale_lookup</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$languageTag</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">bool</span> <code class="parameter">$canonicalize</code><span class="initializer"> = <strong><code>false</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$defaultLocale</code><span class="initializer"> = <strong><code>null</code></strong></span></span><br>): <span class="type"><span class="type">?</span><span class="type">string</span></span></div>

  <p class="para rdfs-comment">
   Searches the items in <code class="parameter">languageTag</code> for the best match to
   the language range specified in <code class="parameter">locale</code> according to
   RFC 4647&#039;s lookup algorithm.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-locale.lookup-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">languageTag</code></dt>

     <dd>

      <p class="para">
       An <span class="type">array</span> containing a list of language tags to compare to
       <code class="parameter">locale</code>. Maximum 100 items allowed.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">locale</code></dt>

     <dd>

      <p class="para">
       The locale to use as the language range when matching.
      </p>
     </dd>

    
     
       <dt>

         <code class="parameter">canonicalize</code>
       </dt>

       <dd>

         <p class="para">
           If true, the arguments will be converted to canonical form before
           matching.
         </p>
       </dd>

     
     
     <dt>
<code class="parameter">defaultLocale</code></dt>

     <dd>

      <p class="para">
       The locale to use if no match is found.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-locale.lookup-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The closest matching language tag or default value.
  </p>
  <p class="para">当 <code class="parameter">locale</code> 的长度超过 <strong><code>INTL_MAX_LOCALE_LEN</code></strong> 时返回 <strong><code>null</code></strong>。</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-locale.lookup-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.4.0</td>
      <td>
       <code class="parameter">defaultLocale</code> is nullable now.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-locale.lookup-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2356">
   <p><strong>示例 #1 <span class="function"><strong>locale_lookup()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DEVA'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DE-1996'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-De'<br /></span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">locale_lookup</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de-DE-1996-x-prv1-prv2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2357">
   <p><strong>示例 #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DEVA'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DE-1996'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-De'<br /></span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">Locale</span><span style="color: #007700">::</span><span style="color: #0000BB">lookup</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de-DE-1996-x-prv1-prv2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
de_de_1996
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-locale.lookup-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="locale.filtermatches.html" class="function" rel="rdfs-seeAlso">locale_filter_matches()</a> - Checks if a language tag filter matches with locale</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>